﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FreeDAM.Domain.Abstract;
using FreeDAM.Domain.Entities;

namespace FreeDAM.WebUI.Areas.Admin.Controllers
{
    public class TagCategoriesController : Controller
    {
        private readonly ITagCategoryRepository TagCategoryRepository;

        public TagCategoriesController(ITagCategoryRepository tagCategoryRepository)
        {
            TagCategoryRepository = tagCategoryRepository;
        }

        public ActionResult Index()
        {
            return View(TagCategoryRepository.All);
        }

        //
        // GET: /Admin/TagCategories/Details/5

        public ActionResult Details(int id)
        {
            return View(TagCategoryRepository.Find(id));
        }

        //
        // GET: /Admin/TagCategories/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /Admin/TagCategories/Create

        [HttpPost]
        public ActionResult Create(TagCategory viewModel)
        {
            ActionResult result = View(viewModel);

            if (ModelState.IsValid)
            {
                TagCategoryRepository.InsertOrUpdate(viewModel);
                TagCategoryRepository.Save();
                result = RedirectToAction("Index");
            }

            return result;
        }

        //
        // GET: /Admin/TagCategories/Edit/5

        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Admin/TagCategories/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Admin/TagCategories/Delete/5

        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /Admin/TagCategories/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
